package cn.js.ccit.flowersmall.goldCoin.service.impl;

import cn.js.ccit.flowersmall.goldCoin.entity.GLDDetailEntity;
import cn.js.ccit.flowersmall.goldCoin.mapper.GLDDetailMapper;
import cn.js.ccit.flowersmall.goldCoin.mapper.GLDUserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;

/**
 * 礼品兑换后被调用的service
 */
@Service
public class GiftGoldCoinService {
    @Resource
    GLDDetailMapper detailMapper;
    @Resource
    GLDUserMapper userMapper;

    public void updateGoldCoin(String userName, Integer goldCoin, String orderNo) {
        GLDDetailEntity entity = new GLDDetailEntity();
        entity.setUserName(userName);
        entity.setGoldCoin(goldCoin);
        entity.setOrderNo(orderNo);
        userMapper.updateGoldCoin(entity);
        entity.setCreateTime(new Date(System.currentTimeMillis()));
        //添加用户金币扣除详细
        detailMapper.addGoldCoin(entity);
    }
}
